/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class CartAddItem
    {
    
        private String ASINField;

        private String offerListingIdField;

        private Decimal? quantityField;

        private String associateTagField;

        private String listItemIdField;

        private  List<MetaData> metaDataField;


        /// <summary>
        /// Gets and sets the ASIN property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ASIN")]
        public String ASIN
        {
            get { return this.ASINField ; }
            set { this.ASINField= value; }
        }



        /// <summary>
        /// Sets the ASIN property
        /// </summary>
        /// <param name="ASIN">ASIN property</param>
        /// <returns>this instance</returns>
        public CartAddItem WithASIN(String ASIN)
        {
            this.ASINField = ASIN;
            return this;
        }



        /// <summary>
        /// Checks if ASIN property is set
        /// </summary>
        /// <returns>true if ASIN property is set</returns>
        public Boolean IsSetASIN()
        {
            return  this.ASINField != null;

        }


        /// <summary>
        /// Gets and sets the OfferListingId property.
        /// </summary>
        [XmlElementAttribute(ElementName = "OfferListingId")]
        public String OfferListingId
        {
            get { return this.offerListingIdField ; }
            set { this.offerListingIdField= value; }
        }



        /// <summary>
        /// Sets the OfferListingId property
        /// </summary>
        /// <param name="offerListingId">OfferListingId property</param>
        /// <returns>this instance</returns>
        public CartAddItem WithOfferListingId(String offerListingId)
        {
            this.offerListingIdField = offerListingId;
            return this;
        }



        /// <summary>
        /// Checks if OfferListingId property is set
        /// </summary>
        /// <returns>true if OfferListingId property is set</returns>
        public Boolean IsSetOfferListingId()
        {
            return  this.offerListingIdField != null;

        }


        /// <summary>
        /// Gets and sets the Quantity property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Quantity")]
        public Decimal Quantity
        {
            get { return this.quantityField.GetValueOrDefault() ; }
            set { this.quantityField= value; }
        }



        /// <summary>
        /// Sets the Quantity property
        /// </summary>
        /// <param name="quantity">Quantity property</param>
        /// <returns>this instance</returns>
        public CartAddItem WithQuantity(Decimal quantity)
        {
            this.quantityField = quantity;
            return this;
        }



        /// <summary>
        /// Checks if Quantity property is set
        /// </summary>
        /// <returns>true if Quantity property is set</returns>
        public Boolean IsSetQuantity()
        {
            return  this.quantityField != null;

        }


        /// <summary>
        /// Gets and sets the AssociateTag property.
        /// </summary>
        [XmlElementAttribute(ElementName = "AssociateTag")]
        public String AssociateTag
        {
            get { return this.associateTagField ; }
            set { this.associateTagField= value; }
        }



        /// <summary>
        /// Sets the AssociateTag property
        /// </summary>
        /// <param name="associateTag">AssociateTag property</param>
        /// <returns>this instance</returns>
        public CartAddItem WithAssociateTag(String associateTag)
        {
            this.associateTagField = associateTag;
            return this;
        }



        /// <summary>
        /// Checks if AssociateTag property is set
        /// </summary>
        /// <returns>true if AssociateTag property is set</returns>
        public Boolean IsSetAssociateTag()
        {
            return  this.associateTagField != null;

        }


        /// <summary>
        /// Gets and sets the ListItemId property.
        /// </summary>
        [XmlElementAttribute(ElementName = "ListItemId")]
        public String ListItemId
        {
            get { return this.listItemIdField ; }
            set { this.listItemIdField= value; }
        }



        /// <summary>
        /// Sets the ListItemId property
        /// </summary>
        /// <param name="listItemId">ListItemId property</param>
        /// <returns>this instance</returns>
        public CartAddItem WithListItemId(String listItemId)
        {
            this.listItemIdField = listItemId;
            return this;
        }



        /// <summary>
        /// Checks if ListItemId property is set
        /// </summary>
        /// <returns>true if ListItemId property is set</returns>
        public Boolean IsSetListItemId()
        {
            return  this.listItemIdField != null;

        }


        /// <summary>
        /// Gets and sets the MetaData property.
        /// </summary>
        [XmlElementAttribute(ElementName = "MetaData")]
        public List<MetaData> MetaData
        {
            get
            {
                if (this.metaDataField == null)
                {
                    this.metaDataField = new List<MetaData>();
                }
                return this.metaDataField;
            }
            set { this.metaDataField =  value; }
        }



        /// <summary>
        /// Sets the MetaData property
        /// </summary>
        /// <param name="list">MetaData property</param>
        /// <returns>this instance</returns>
        public CartAddItem WithMetaData(params MetaData[] list)
        {
            foreach (MetaData item in list)
            {
                MetaData.Add(item);
            }
            return this;
        }          
 


        /// <summary>
        /// Checks if MetaData property is set
        /// </summary>
        /// <returns>true if MetaData property is set</returns>
        public Boolean IsSetMetaData()
        {
            return (MetaData.Count > 0);
        }




        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetASIN()) {
                xml.Append("<ASIN>");
                xml.Append(EscapeXML(this.ASIN));
                xml.Append("</ASIN>");
            }
            if (IsSetOfferListingId()) {
                xml.Append("<OfferListingId>");
                xml.Append(EscapeXML(this.OfferListingId));
                xml.Append("</OfferListingId>");
            }
            if (IsSetQuantity()) {
                xml.Append("<Quantity>");
                xml.Append(this.Quantity);
                xml.Append("</Quantity>");
            }
            if (IsSetAssociateTag()) {
                xml.Append("<AssociateTag>");
                xml.Append(EscapeXML(this.AssociateTag));
                xml.Append("</AssociateTag>");
            }
            if (IsSetListItemId()) {
                xml.Append("<ListItemId>");
                xml.Append(EscapeXML(this.ListItemId));
                xml.Append("</ListItemId>");
            }
            List<MetaData> metaDataList = this.MetaData;
            foreach (MetaData metaData in metaDataList) {
                xml.Append("<MetaData>");
                xml.Append(metaData.ToXMLFragment());
                xml.Append("</MetaData>");
            }
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}